<?php foreach ($edit_data as $key): ?>
  <div class="ibox float-e-margins">
    <div class="ibox-title" style="border: none;">
      <h5 style="color: #00afef"><i>View</i></h5>
        
    </div>
    <div class="ibox-content">
      <form class="form-horizontal" id="assetForm_v">
      <input type="hidden" name="asset_id" value="<?php echo $key->asset_id; ?>">
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Asset Code</label>
            <div class="col-lg-8">
                <input readonly name="assetCode" value="<?php echo $key->asset_code; ?>" type="text" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Main Category</label>
            <div class="col-lg-8">
                <select disabled name="mainCat" class="form-control">
                    <option value="">--</option>
                    <?php foreach($main_category as $mc): ?>
                    <option value="<?php echo $mc->category_code; ?>" <?php echo $key->main_cat_code == $mc->category_code ? 'selected' : ''; ?>><?php echo $mc->description; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Sub Category</label>
            <div disabled class="col-lg-8">
                <select disabled name="subCat" class="form-control">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Asset Name</label>
            <div class="col-lg-8">
                <input disabled type="text" value="<?php echo $key->asset_name; ?>" name="assetName" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Department</label>
            <div class="col-lg-8">
                <select disabled name="department" class="form-control">
                    <option value="">--</option>
                    <?php foreach($dep as $s): ?>
                    <option value="<?php echo $s->lookup_code; ?>" <?php echo $key->department == $s->lookup_code ? 'selected' : '' ; ?>><?php echo $s->meaning; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Location</label>
            <div class="col-lg-8">
                <select disabled name="location" class="form-control">
                    <option value="">--</option>
                    <?php foreach($location as $mc): ?>
                    <option value="<?php echo $mc->location_code; ?>" <?php echo $key->location == $mc->location_code ? 'selected' : ''; ?>><?php echo $mc->description; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Purchase Date</label>
            <div class="col-lg-8">
                <input type="date" value="<?php echo $key->purchase_date; ?>" disabled name="purchaseDate" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Asset Description</label>
            <div class="col-lg-8">
                <input type="text" disabled name="assetDescription" value="<?php echo $key->asset_description; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Brand Name</label>
            <div class="col-lg-8">
                <input type="text" disabled name="brandName" value="<?php echo $key->brand_name; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Model</label>
            <div class="col-lg-8">
                <input type="text" disabled name="model" value="<?php echo $key->model; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Asset Serial Number</label>
            <div class="col-lg-8">
                <input type="text" disabled name="assetSerNum" value="<?php echo $key->serial_num; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Asset Currency</label>
            <div class="col-lg-8">
                <select disabled name="assetCurrency" class="form-control">
                    <option value="">--</option>
                    <?php foreach($asset_currency as $mc): ?>
                    <option value="<?php echo $mc->lookup_code; ?>" <?php echo $mc->lookup_code == $key->currency ? 'selected' : ''; ?>><?php echo $mc->meaning; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Asset Cost</label>
            <div class="col-lg-8">
                <input disabled type="number" value="<?php echo $key->asset_cost; ?>" name="assetCost" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Depreciation Years</label>
            <div class="col-lg-8">
                <input disabled type="text" name="dep_yrs" value="<?php echo $key->depreciation_yrs; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Salvage Value</label>
            <div class="col-lg-8">
                <input type="number" disabled value="<?php echo $key->salvage_value; ?>" name="salvageValue" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Book Value</label>
            <div class="col-lg-8">
                <input type="text" readonly name="bookValue" value="<?php echo $key->book_value; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label style="text-align: right;" class="col-lg-3 control-label">Depreciation Value</label>
            <div class="col-lg-8">
                <input type="text" disabled name="depValue" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Contract Vendor</label>
            <div class="col-lg-8">
                <input type="text" disabled name="contractVendor" value="<?php echo $key->contract_vendor; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Asset Status</label>
            <div class="col-lg-8">
                 <select disabled name="assetStatus" class="form-control">
                    <option value="">--</option>
                    <?php foreach($asset_status as $mc): ?>
                    <option value="<?php echo $mc->lookup_code; ?>" <?php echo $mc->lookup_code == $key->status ? 'selected' : ''; ?>><?php echo $mc->meaning; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Asset Owner</label>
            <div class="col-lg-8">
                <select disabled name="assetOwner" class="form-control">
                    <option value="">--</option>
                    <?php foreach($employee as $mc): ?>
                    <option value="<?php echo $mc->employee_id; ?>" <?php echo $key->owner == $mc->employee_id ? 'selected' : ''; ?>><?php echo $mc->first_name.' '.$mc->last_name; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Depreciation Cycle</label>
            <div class="col-lg-8">
                <select disabled name="depCycle" class="form-control">
                    <option value="">--</option>
                    <?php foreach($depre_cycle as $mc): ?>
                    <option value="<?php echo $mc->lookup_code; ?>" <?php echo $key->depre_cycle == $mc->lookup_code ? 'selected' : ''; ?>><?php echo $mc->meaning; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
        </div>
         <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Last Depreciation Run</label>
            <div class="col-lg-8">
                <input readonly type="date" name="depLastRun" value="<?php echo $key->depre_last_run; ?>" class="form-control">
            </div>
        </div>
        <div class="form-group">
            <label style="text-align: right;" class="col-lg-3 control-label">Retirement Date</label>
            <div class="col-lg-8">
                <input type="text" value="<?php echo $key->retirement_date; ?>" readonly name="retirementDate" class="form-control">
            </div>
        </div>
      </div>
      </form>
    </div>
  </div>
<?php endforeach;?>
  <script type="text/javascript">
  $(document).ready(function() {
    $('#assetForm_v').data('serialize',$('#assetForm_v').serialize());

    $('select').chosen({width: '100%'});
  

    $(function(){
      $.ajax({
        url: "<?php echo base_url($this->session->userdata('forajax') . '/getSubCat'); ?>",
        method: "POST",
        data: { 'cat_code' : $('#assetForm_v select[name=mainCat]').val() },
        dataType: 'json',
        success: function(data){
          var tmp = '';
          $.each(data,function(i, item) {
            tmp += '<option value="'+data[i].sub_category_code +'">'+ data[i].description +'</option>';
          });
          $('#assetForm_v select[name=subCat]').html(tmp);
          $("select").trigger("chosen:updated");
        }
      });
    });

        function alert_cancel(){
                if($('#assetForm_v').serialize()!=$('#assetForm_v').data('serialize')){
                // Form has changed!!!
                swal({
                  title: "Are you sure?",
                  text: "Your work will not be save",
                  type: "warning",
                  showCancelButton: true,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "Leave",
                  cancelButtonText: "Stay",
                  closeOnConfirm: true,
                  closeOnCancel: true },
              function (isConfirm) {
                  if (isConfirm) {
                    swal("success");
                      close_add(); active_search();
                      notifyClass("clear","");
                  } else {
                      swal("Cancelled");
                  }
              });
                }else{
                    close_add(); active_search();
                    notifymsg("hide","hide");
                }
            }
        $('#cancel_view').click(function(){
            alert_cancel();
        });

        $('#viewX').click(function(){
            alert_cancel();
        });
  });
  </script>